/**
 * 
 */
package third_assignment;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
//import java.text.DateFormat;
//import java.util.Date;
import java.util.LinkedList;

import second_assignment.Consts_2nd;
import fourth_assignment.Request;

/**
 * a wrapper class for running and testing project functionality.
 * 
 * @author Peretz Oded, Castel Maayan, Farchy Ofir.
 */
public class MainApp_3rd {

    @SuppressWarnings("unchecked")
    public static void main(String[] args) 
    {
        //DateFormat shortTime = DateFormat.getTimeInstance(DateFormat.LONG);
        //System.out.println(shortTime.format(new Date()));
        StaticSimulator simulator = new StaticSimulator();
        
        LinkedList<Request> requestList = new LinkedList<Request>();
        
        int[] clientResults = new int[3];
        int totalClients = 0;
        int totalRejected = 0;
        int totalCost = 0;
        System.out.println("Lambda = " + Consts_2nd.Lambda);
        
        // RUN A WEEK'S SIMULATION
        for(int i = 1 ; i <= 7 ; ++i)
        {
            int currCost = 0;
        	System.out.println("Day " + i);
        	//System.out.println(shortTime.format(new Date()));
        	// RUN A DAY'S SIMULATION
        	clientResults = simulator.getManager().ClientsManagment(requestList);
        	totalClients += clientResults[0];
            totalRejected += clientResults[1];
            //currCost = clientResults[2];

            FileOutputStream fos = null;
    		ObjectOutputStream out = null;
    		try
    		{
    			String filename = "requests" + i;
    			fos = new FileOutputStream(filename);
    		    out = new ObjectOutputStream(fos);
    		    out.writeObject(requestList);
    		    out.close();
    		}
    		catch(IOException ex)
    		{
    			ex.printStackTrace();
    			System.exit(0);
    		}
            
            requestList.clear();
            
            System.gc();
            // PREFORM END OF DAY MOVIE UPDATES
            currCost = simulator.EndOfDay(i);
            System.out.println("Total cost of STATIC ALGORITHM today is: " + currCost);
            totalCost += currCost;
        }
        System.out.println("**********************************************************************");
        System.out.println("Total rejected clients percentage is: " + ((double)totalRejected/((double)totalClients))*100);
        System.out.println("Total clients: " + totalClients + ", Total rejects: " + totalRejected + ", Total cost: " + totalCost);
        //System.out.println(shortTime.format(new Date()));
    }
}
